import request from '/@/utils/request';
import { useUrlUtil } from '/@/utils/urlUtil';
import { BaseResponse } from '/@/interfaces/BaseModel';
import { FileInfoApi } from '/@/enums/jdfsystem-api-enum';
import { BaseRequest } from '/@/interfaces/BaseModel';
import {
    FileInfoSearchParamModel,
    FileInfoListModel,
    FileInfoDetailModel,
    FileInfoAddParamModel,
    FileInfoDeleteParamModel
} from '/@/interfaces/JdfsystemModel';

function useFileInfo() {
    const url = (import.meta.env.VITE_API_URL as string);
    const apiBaseUrl = (import.meta.env.VITE_API_BASE_PATH as string);
    return {
        list: function (payload: BaseRequest<FileInfoSearchParamModel>) {
            return request.post<BaseResponse<FileInfoListModel[]>>(FileInfoApi.LIST, payload);
        },
        listFileInfo: function (payload: BaseRequest<Array<string>>) {
            return request.post<BaseResponse<Array<FileInfoListModel>>>(FileInfoApi.LIST_FILE_INFO, payload);
        },
        detail: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<FileInfoDetailModel>>(useUrl.joinParam(FileInfoApi.DETAIL, payload));
        },
        add: function (payload: FileInfoAddParamModel) {
            return request.post<BaseResponse<boolean>>(FileInfoApi.ADD, payload);
        },
        del: function (payload: BaseRequest<Array<string>>) {
            return request.post<BaseResponse<boolean>>(FileInfoApi.DEL, payload);
        },
        view: function (fileId: string): string {
            return url + apiBaseUrl + FileInfoApi.VIEW + fileId;
        },
        uploadUrl: function (): string {
            return url + apiBaseUrl + FileInfoApi.UPLOAD;
        },
        trust: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<Boolean>>(useUrl.joinParam(FileInfoApi.TRUST, payload));
        },
    };
}

export default useFileInfo;